package com.wzy.ssm.util;

public class IdUtil {

    private static IdGenerator idGenerator;
    private static int last = 0;

    //生成16位长整型数字id
    public static Long nextId(){
       if(idGenerator == null){
           idGenerator= new IdGenerator(0);
       }
       return idGenerator.nextId();
    }

    //生成9位整型数字id
    public static Integer nextId9(){
        int LIMIT = 1000000000;
        int id = (int)(System.currentTimeMillis() % LIMIT);
        if ( id <= last ) {
            id = (last + 1) ;
        }
        return last = id;
    }

    public static void main(String[] args) {
        System.out.println(IdUtil.nextId9());
        System.out.println(IdUtil.nextId9());
        System.out.println(IdUtil.nextId9());
        System.out.println(IdUtil.nextId());
        System.out.println(IdUtil.nextId());
        System.out.println(IdUtil.nextId());
        System.out.println(IdUtil.nextId());
        System.out.println(IdUtil.nextId());
    }
}
